﻿Public Class _Default
    Inherits Page

    Protected Overrides Sub InitializeCulture()
        With ProjectSettings
            System.Threading.Thread.CurrentThread.CurrentUICulture = .Language
            System.Threading.Thread.CurrentThread.CurrentCulture = .Language
        End With

        MyBase.InitializeCulture()
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            With ProjectSettings
                .Load() 'will return false if no project is selected; however don't want to navigate to configure page if just using for first time, so allow it
                'If .Load Then
                Select Case .Language.Name.Substring(0, 2)
                    Case "en" : cboLanguage.SelectedIndex = 0
                    Case "es" : cboLanguage.SelectedIndex = 1
                End Select
                'End If
            End With
            'writedebug("===============================================================================")
            'writedebug("Starting session...")
            'ScriptManager.RegisterStartupScript(Me, Me.GetType(), "WRDB", "alert('Writing debug information to debug.txt!');", True)
        End If
        'If Project Is Nothing OrElse HttpContext.Current.Session("ProjectDataset") Is Nothing Then
        '    HttpContext.Current.Response.Redirect("Configure.aspx")
        'End If
    End Sub

    Protected Sub cboLanguage_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboLanguage.SelectedIndexChanged
        'save new selections as cookies then display the select data form (note: es-CO used so SI units are displayed)
        With ProjectSettings
            .Language = New Globalization.CultureInfo(CStr(Choose(cboLanguage.SelectedIndex + 1, "en-US", "es-CO")))
            .Save()
            HttpContext.Current.Response.Redirect("Default.aspx") 'reload with new language settings
        End With
    End Sub

End Class